#!/usr/bin/env node
const { Command } = require('commander');
const program = new Command();
const inquirer = require('inquirer');
console.log('欢迎使用Yl 脚手架');

const download = require('download-git-repo');
const downloadAdress = name => {

  const gits = {
    'template-v2': `direct:https://gitee.com/loserjohn/subsystem-template-v2s.git#master`,

    'template-v3': `direct:https://gitee.com/loserjohn/subsystem-template-v3s.git#master`,


  }
  return gits[name] || ''
};



//下载
const downloadCallback = (err) => {

  if (err) {
    console.log('初始化失败', err)
  } else {
    console.log(`项目模板初始化成功`)
  }

}

console.log(123);

try {
  program
    .command('create')
    .argument('<string>', 'project name')
    .description('初始化项目')
    .action(async (arg) => {
      // console.log(456);
      const answer = await inquirer.prompt([
        //...
        {
          type: 'list',
          message: '使用哪个版本的开发模板',
          name: 'name',
          choices: ['template-v2', 'template-v3'],
        },
      ]);
      console.log(`${arg}项目模板下载中...`)
      download(
        downloadAdress(answer.name),
        `${arg}`,	// path
        { clone: true },
        downloadCallback ,	// callback
      );
    });
  program.parse();
} catch (error) {
  console.log(error);
}


